package com.example.forum.commen;

import com.fasterxml.jackson.annotation.JsonInclude;

public class AppResult<T> {
    //状态码
    @JsonInclude(JsonInclude.Include.ALWAYS)//无论什么时候都要序列化
    private int code;
    //描述信息
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private String message;
    //具体数据
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private T data;
    /*
    * 构造方法
    * */
    public AppResult(int code, String message) {
        this(code,message,null);
    }

    public AppResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    /*成功
     * */
    public static AppResult success()  {
        return  new AppResult(ResultCode.SUCESS.getCode(), ResultCode.SUCESS.getMessage());
    }
    public static AppResult success(String s) {
        return new AppResult(ResultCode.SUCESS.getCode(),s);
    }
    public static <T> AppResult<T> success(T data) {
        return new AppResult<>(ResultCode.SUCESS.getCode(),ResultCode.SUCESS.getMessage(),data);
    }
    public static <T> AppResult<T> sucess(String message,T date) {
        return new AppResult<>(ResultCode.SUCESS.getCode(),message,date);
    }
    /*
    * 失败
    * */
    public static AppResult failed() {
        return new AppResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage());
    }
    public static AppResult failed(String message) {
        return new AppResult(ResultCode.FAILED.getCode(), message);
    }
    public static AppResult failed(ResultCode resultCode) {
        return new AppResult(resultCode.getCode(), resultCode.getMessage());
    }





    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }
}
